home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Web Graphics with Shout 3D
/
Interactive Web Graphics With Shout 3D.iso
/
mac
/
Shout3Ddemo
/
Shout3d_runtime
/
codebase
/
custom_nodes
/
DEFNamePickerEffect.java
< prev
next >
Wrap
Text File
|
2000-10-27
|
3KB
|
109 lines
/**
Company: Eyematic Interfaces
Project: Shout3D Core
Class: DEFNamePickerEffect
Date: June 7, 2000
Description: A simple example of a PostRenderEffect that displays the DEF Name of a picked object
(C) Copyright Eyematic Interfaces, Inc. - 1997/1998/1999/2000 - All rights reserved
*/
package custom_nodes;
import shout3d.core.*;
import shout3d.*;
import shout3d.core.awt.*;
import java.awt.*;
import java.awt.image.*;
/**
* DEFNamePickerEffect
*
* @author Jim Stewartson
* @author Hugues Labbe
* @author Paul Isaacs
*
*/
public class DEFNamePickerEffect extends LabelEffect implements DeviceObserver
{
Picker picker;
int x;
int y;
boolean mouseIsInPanel = false;
/**
* Constructs a default DEFNamePickerEffect node.
*/
public DEFNamePickerEffect()
{
super();
}
/**
* When the viewer is set, register with it to receive DeviceInput.
*/
public void setViewer(Shout3DViewer v){
// Unregister with old viewer
if (getViewer() != null)
getViewer().getDeviceListener().removeDeviceObserver(this, "MouseInput");
// Change viewers.
super.setViewer(v);
// Register with new viewer
if (getViewer() != null){
getViewer().getDeviceListener().addDeviceObserver(this, "MouseInput", null);
picker = getViewer().getNewPicker();
}
}
public boolean onDeviceInput(DeviceInput di, Object userData)
{
if ( !(di instanceof MouseInput))
return false;
MouseInput mi = (MouseInput)di;
switch (mi.which) {
case MouseInput.DOWN:
case MouseInput.DRAG:
case MouseInput.MOVE:
x = mi.x;
y = mi.y;
mouseIsInPanel = true;
break;
case MouseInput.ENTER:
mouseIsInPanel = true;
break;
case MouseInput.EXIT:
mouseIsInPanel = false;
break;
default:
break;
}
return false;
}
public void filter(Graphics g, int surface_pixel_bits[], float z_buffer[], int deviceWidth, int deviceHeight)
{
if (mouseIsInPanel) {
Node[] node = picker.pickClosest(x, y);
if (node == null)
return;
// Get name of bottom-most named node on the path:
String DEFName = null;
for (int i = node.length-1; i >= 0; i--) {
if (node[i].getDEFName() != null) {
DEFName = node[i].getDEFName();
break;
}
}
if (DEFName != null) {
label_text.setValue(DEFName);
int offsety = 21;
xPosition.setValue(x);
yPosition.setValue(y+offsety);
super.filter(g, surface_pixel_bits, z_buffer, deviceWidth, deviceHeight);
}
}
}
}